<?php

class DanTri {

    var $links = array();
    var $title = "";
    var $intro = "";
    var $content = "";
    var $imgurl = "";

    function Init() {
        $this->title = "";
        $this->intro = "";
        $this->content = "";
        $this->imageurl = "";
    }

    function GetLink($link) {
        $link = trim($link);
        $document = FetchDataString($link);

        if (getFileExt($link) == 'rss') {
            $rss = RssReader($link);

            for ($i = 0; $i < sizeof($rss); $i++)
                array_push($this->links, $rss[$i]['link']);
        } else {
            preg_match_all('/\bhttp:\/\/dantri.com.vn[-A-Z0-9+&@#\/%?=~_|$!:,.;]*[A-Z0-9+&@#\/%=~_|htm$]/i', $document, $result, PREG_PATTERN_ORDER);

            $n = sizeof($result[0]);

            for ($i = 0; $i < $n; $i++) {
                $flag = 0;
                for ($j = $i + 1; $j < $n; $j++)
                    if ($result[0][$j] == $result[0][$i])
                        $flag = 1;

                if ($flag == 0)
                    array_push($this->links, $result[0][$i]);
            }
        }

        return true;
    }

    function GetInfo($link) {
        $this->Init();

        $document = FetchDataString($link);

        if (!preg_match('%<div class="fon31 mt1">(.*?)</div>%i', $document, $regs))
            return false;

        $this->title = $regs[1];

        if (!preg_match('%<div class="fon33 mt1">(.*?)</div>%si', $document, $regs))
            return false;

        $this->intro = $regs[1];

        if (!preg_match('%<div class="fon34 mt3 mr2 fon43">(.*?)<input type=\'hidden\' value=\'.*\' id=\'hidNextUsing\'/></div>%si', $document, $regs))
            if (!preg_match('%<div class="fon34 mt3 mr2 fon43">(.*?)</div>%si', $document, $regs))
                return false;

        $this->content = $regs[1];

        if (!preg_match('/<img.*?src="(.*?)".*?>/i', $this->content, $regs))
            $this->imgurl = "";
        else
            $this->imgurl = $regs[1];

        return true;
    }

}

?>
